﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Waker.Common;

namespace Waker.SystemSetting
{
    public partial class FormCompany : Waker.Base.FormBasePop
    {
        public FormCompany()
        {
            InitializeComponent();
        }
        private DataTable _Dt;
        private void FormCompany_Load(object sender, EventArgs e)
        {
            _Dt = new BAL.BAL_SystemSetting().GetTableByTableName("T_Company");
            if (_Dt == null)
            {
                return;
            }
            if (_Dt.Rows.Count < 1)
                _Dt.Rows.Add(_Dt.NewRow());
            ControlUtil.BindData(this.Controls, _Dt);
        }
        protected override void FormSave()
        {
            if (_Dt == null)
                return;
            base.errorPop.ClearErrors();
            if (string.IsNullOrEmpty(txtName.Text))
            {
                base.errorPop.SetError(txtName, "公司名称不能为空");
                return;
            }
            this.BindingContext[_Dt].EndCurrentEdit();
            var isOk = new BAL.BAL_SystemSetting().SaveCompany(_Dt);
            if (isOk)
            {
                UI.ShowInfo("保存成功");
            }
            else
            {
                UI.ShowError("保存失败");
            }
        }
    }
}
